package JDBC;

import com.jcraft.jsch.*;

public class SFTPSender {
    public static void main(String[] args) {
        String host = "8.130.104.107";
        String username = "root";
        String password = "G180813y";
        String remoteFilePath = "/www/wwwroot/root/ftprest1.txt";
        int port = 22; // SFTP默认端口

        String localFilePath = "D:\\ftprest";
        JSch jsch = new JSch();
        try {
            Session session = jsch.getSession(username, host, port);
            session.setConfig("StrictHostKeyChecking", "no"); // 跳过主机密钥检查
            session.setPassword(password);
            session.connect();

            ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
            channelSftp.connect();

            channelSftp.put(localFilePath, remoteFilePath);

            channelSftp.disconnect();
            session.disconnect();

            System.out.println("文件发送成功！");
        } catch (JSchException | SftpException e) {
            e.printStackTrace();
        }
    }

}
